package com.crlclr.data.qzone
{
	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.utils.ByteArray;
	import com.crlclr.data.AlbumData;

	public class PhotosXMLLoader extends URLLoader
	{
		public var bookData:AlbumData;
		public function PhotosXMLLoader()
		{
			super();
			this.dataFormat=URLLoaderDataFormat.BINARY;
			this.addEventListener(Event.COMPLETE,completeHandler);
		}		
		
		private function completeHandler(event:Event):void{
			this.removeEventListener(Event.COMPLETE,completeHandler);
			
			var photos:Array=new Array();
			
			var bytes:ByteArray=this.data;
			var xml:XML=new XML(bytes.readMultiByte(bytes.bytesAvailable, "gb2312"));
			var pictures:XMLList=xml.descendants("pic");
			
			var picture:PictureVO;
			for each(var pictureData:XML in pictures){
				picture=new PictureVO();
				picture.bindXML(pictureData);
				
				photos.push(picture);
			}
			
			this.bookData=new AlbumData(photos);
			
			//this.dispatchEvent(new Event(Event.COMPLETE));
		}
		
	}
}